.class public Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker08;
.super Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker;
.source "WebSocketServerHandshaker08.java"


# static fields
.field public static final WEBSOCKET_08_ACCEPT_GUID:Ljava/lang/String; = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"

.field private static final logger:Lorg/jboss/netty/logging/InternalLogger;


# instance fields
.field private final allowExtensions:Z


# direct methods
.method static constructor <clinit>()V
    .locals 1

    .prologue
    .line 46
    const-class v0, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker08;

    invoke-static {v0}, Lorg/jboss/netty/logging/InternalLoggerFactory;->getInstance(Ljava/lang/Class;)Lorg/jboss/netty/logging/InternalLogger;

    move-result-object v0

    sput-object v0, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker08;->logger:Lorg/jboss/netty/logging/InternalLogger;

    return-void
.end method

.method public constructor <init>(Ljava/lang/String;Ljava/lang/String;Z)V
    .locals 1
    .parameter "webSocketURL"
    .parameter "subprotocols"
    .parameter "allowExtensions"

    .prologue
    .line 64
    sget-object v0, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketVersion;->V08:Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketVersion;

    invoke-direct {p0, v0, p1, p2}, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker;-><init>(Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketVersion;Ljava/lang/String;Ljava/lang/String;)V

    .line 65
    iput-boolean p3, p0, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker08;->allowExtensions:Z

    .line 66
    return-void
.end method


# virtual methods
.method public close(Lorg/jboss/netty/channel/Channel;Lorg/jboss/netty/handler/codec/http/websocketx/CloseWebSocketFrame;)Lorg/jboss/netty/channel/ChannelFuture;
    .locals 2
    .parameter "channel"
    .parameter "frame"

    .prologue
    .line 158
    invoke-interface {p1, p2}, Lorg/jboss/netty/channel/Channel;->write(Ljava/lang/Object;)Lorg/jboss/netty/channel/ChannelFuture;

    move-result-object v0

    .line 159
    .local v0, f:Lorg/jboss/netty/channel/ChannelFuture;
    sget-object v1, Lorg/jboss/netty/channel/ChannelFutureListener;->CLOSE:Lorg/jboss/netty/channel/ChannelFutureListener;

    invoke-interface {v0, v1}, Lorg/jboss/netty/channel/ChannelFuture;->addListener(Lorg/jboss/netty/channel/ChannelFutureListener;)V

    .line 160
    return-object v0
.end method

.method public handshake(Lorg/jboss/netty/channel/Channel;Lorg/jboss/netty/handler/codec/http/HttpRequest;)Lorg/jboss/netty/channel/ChannelFuture;
    .locals 13
    .parameter "channel"
    .parameter "req"

    .prologue
    .line 110
    sget-object v8, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker08;->logger:Lorg/jboss/netty/logging/InternalLogger;

    invoke-interface {v8}, Lorg/jboss/netty/logging/InternalLogger;->isDebugEnabled()Z

    move-result v8

    if-eqz v8, :cond_0

    .line 111
    sget-object v8, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker08;->logger:Lorg/jboss/netty/logging/InternalLogger;

    const-string v9, "Channel %s WS Version 8 server handshake"

    const/4 v10, 0x1

    new-array v10, v10, [Ljava/lang/Object;

    const/4 v11, 0x0

    invoke-interface {p1}, Lorg/jboss/netty/channel/Channel;->getId()Ljava/lang/Integer;

    move-result-object v12

    aput-object v12, v10, v11

    invoke-static {v9, v10}, Ljava/lang/String;->format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v9

    invoke-interface {v8, v9}, Lorg/jboss/netty/logging/InternalLogger;->debug(Ljava/lang/String;)V

    .line 114
    :cond_0
    new-instance v6, Lorg/jboss/netty/handler/codec/http/DefaultHttpResponse;

    sget-object v8, Lorg/jboss/netty/handler/codec/http/HttpVersion;->HTTP_1_1:Lorg/jboss/netty/handler/codec/http/HttpVersion;

    sget-object v9, Lorg/jboss/netty/handler/codec/http/HttpResponseStatus;->SWITCHING_PROTOCOLS:Lorg/jboss/netty/handler/codec/http/HttpResponseStatus;

    invoke-direct {v6, v8, v9}, Lorg/jboss/netty/handler/codec/http/DefaultHttpResponse;-><init>(Lorg/jboss/netty/handler/codec/http/HttpVersion;Lorg/jboss/netty/handler/codec/http/HttpResponseStatus;)V

    .line 116
    .local v6, res:Lorg/jboss/netty/handler/codec/http/HttpResponse;
    const-string v8, "Sec-WebSocket-Key"

    invoke-interface {p2, v8}, Lorg/jboss/netty/handler/codec/http/HttpRequest;->getHeader(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v3

    .line 117
    .local v3, key:Ljava/lang/String;
    if-nez v3, :cond_1

    .line 118
    new-instance v8, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketHandshakeException;

    const-string v9, "not a WebSocket request: missing key"

    invoke-direct {v8, v9}, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketHandshakeException;-><init>(Ljava/lang/String;)V

    throw v8

    .line 120
    :cond_1
    new-instance v8, Ljava/lang/StringBuilder;

    invoke-direct {v8}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v8, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v8

    const-string v9, "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"

    invoke-virtual {v8, v9}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v8

    invoke-virtual {v8}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    .line 121
    .local v1, acceptSeed:Ljava/lang/String;
    sget-object v8, Lorg/jboss/netty/util/CharsetUtil;->US_ASCII:Ljava/nio/charset/Charset;

    invoke-virtual {v1, v8}, Ljava/lang/String;->getBytes(Ljava/nio/charset/Charset;)[B

    move-result-object v8

    invoke-static {v8}, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketUtil;->sha1([B)[B

    move-result-object v7

    .line 122
    .local v7, sha1:[B
    invoke-static {v7}, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketUtil;->base64([B)Ljava/lang/String;

    move-result-object v0

    .line 124
    .local v0, accept:Ljava/lang/String;
    sget-object v8, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker08;->logger:Lorg/jboss/netty/logging/InternalLogger;

    invoke-interface {v8}, Lorg/jboss/netty/logging/InternalLogger;->isDebugEnabled()Z

    move-result v8

    if-eqz v8, :cond_2

    .line 125
    sget-object v8, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker08;->logger:Lorg/jboss/netty/logging/InternalLogger;

    const-string v9, "WS Version 8 Server Handshake key: %s. Response: %s."

    const/4 v10, 0x2

    new-array v10, v10, [Ljava/lang/Object;

    const/4 v11, 0x0

    aput-object v3, v10, v11

    const/4 v11, 0x1

    aput-object v0, v10, v11

    invoke-static {v9, v10}, Ljava/lang/String;->format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v9

    invoke-interface {v8, v9}, Lorg/jboss/netty/logging/InternalLogger;->debug(Ljava/lang/String;)V

    .line 128
    :cond_2
    sget-object v8, Lorg/jboss/netty/handler/codec/http/HttpResponseStatus;->SWITCHING_PROTOCOLS:Lorg/jboss/netty/handler/codec/http/HttpResponseStatus;

    invoke-interface {v6, v8}, Lorg/jboss/netty/handler/codec/http/HttpResponse;->setStatus(Lorg/jboss/netty/handler/codec/http/HttpResponseStatus;)V

    .line 129
    const-string v8, "Upgrade"

    const-string v9, "WebSocket"

    invoke-virtual {v9}, Ljava/lang/String;->toLowerCase()Ljava/lang/String;

    move-result-object v9

    invoke-interface {v6, v8, v9}, Lorg/jboss/netty/handler/codec/http/HttpResponse;->addHeader(Ljava/lang/String;Ljava/lang/Object;)V

    .line 130
    const-string v8, "Connection"

    const-string v9, "Upgrade"

    invoke-interface {v6, v8, v9}, Lorg/jboss/netty/handler/codec/http/HttpResponse;->addHeader(Ljava/lang/String;Ljava/lang/Object;)V

    .line 131
    const-string v8, "Sec-WebSocket-Accept"

    invoke-interface {v6, v8, v0}, Lorg/jboss/netty/handler/codec/http/HttpResponse;->addHeader(Ljava/lang/String;Ljava/lang/Object;)V

    .line 132
    const-string v8, "Sec-WebSocket-Protocol"

    invoke-interface {p2, v8}, Lorg/jboss/netty/handler/codec/http/HttpRequest;->getHeader(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v5

    .line 133
    .local v5, protocol:Ljava/lang/String;
    if-eqz v5, :cond_3

    .line 134
    const-string v8, "Sec-WebSocket-Protocol"

    invoke-virtual {p0, v5}, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker08;->selectSubprotocol(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v9

    invoke-interface {v6, v8, v9}, Lorg/jboss/netty/handler/codec/http/HttpResponse;->addHeader(Ljava/lang/String;Ljava/lang/Object;)V

    .line 137
    :cond_3
    invoke-interface {p1, v6}, Lorg/jboss/netty/channel/Channel;->write(Ljava/lang/Object;)Lorg/jboss/netty/channel/ChannelFuture;

    move-result-object v2

    .line 140
    .local v2, future:Lorg/jboss/netty/channel/ChannelFuture;
    invoke-interface {p1}, Lorg/jboss/netty/channel/Channel;->getPipeline()Lorg/jboss/netty/channel/ChannelPipeline;

    move-result-object v4

    .line 141
    .local v4, p:Lorg/jboss/netty/channel/ChannelPipeline;
    const-class v8, Lorg/jboss/netty/handler/codec/http/HttpChunkAggregator;

    invoke-interface {v4, v8}, Lorg/jboss/netty/channel/ChannelPipeline;->remove(Ljava/lang/Class;)Lorg/jboss/netty/channel/ChannelHandler;

    .line 142
    const-class v8, Lorg/jboss/netty/handler/codec/http/HttpRequestDecoder;

    const-string v9, "wsdecoder"

    new-instance v10, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocket08FrameDecoder;

    const/4 v11, 0x1

    iget-boolean v12, p0, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocketServerHandshaker08;->allowExtensions:Z

    invoke-direct {v10, v11, v12}, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocket08FrameDecoder;-><init>(ZZ)V

    invoke-interface {v4, v8, v9, v10}, Lorg/jboss/netty/channel/ChannelPipeline;->replace(Ljava/lang/Class;Ljava/lang/String;Lorg/jboss/netty/channel/ChannelHandler;)Lorg/jboss/netty/channel/ChannelHandler;

    .line 143
    const-class v8, Lorg/jboss/netty/handler/codec/http/HttpResponseEncoder;

    const-string v9, "wsencoder"

    new-instance v10, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocket08FrameEncoder;

    const/4 v11, 0x0

    invoke-direct {v10, v11}, Lorg/jboss/netty/handler/codec/http/websocketx/WebSocket08FrameEncoder;-><init>(Z)V

    invoke-interface {v4, v8, v9, v10}, Lorg/jboss/netty/channel/ChannelPipeline;->replace(Ljava/lang/Class;Ljava/lang/String;Lorg/jboss/netty/channel/ChannelHandler;)Lorg/jboss/netty/channel/ChannelHandler;

    .line 145
    return-object v2
.end method
